#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=150, inf=0x7ffffff;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

class Net {
public:
  static const int maxn=154, maxm=8*maxn, s=1, t=2;
  int n, m=1, mincost=0, ind[maxn+1], to[2*maxm+1], link[2*maxm+1], val[2*maxm+1], cost[2*maxm+1], dis[maxn+1], d[maxn+1], cur[maxn+1];
  bool flag=false, vis[maxn+1];

  void addSide(int u, int v, int w, int c) {
    if (w<0) {
      flag = true;
    }
    m++;
    to[m] = v;
    val[m] = w;
    cost[m] = c;
    link[m] = ind[u];
    ind[u] = m;
  }

  void addTwoSide(int u, int v, int down, int up, int cost) {
    addSide(u+2, v+2, up-down, cost);
    addSide(v+2, u+2, 0, -cost);
    d[u+2]-=down, d[v+2]+=down;
    mincost += down*cost;
  }

  void build(int n) {
    this->n = n+2;
    for (int i=3; i<=n+2; i++) {
      if (d[i]>0) {
	addSide(s, i, d[i], 0);
	addSide(i, s, 0, 0);
      } else if (d[i]<0) {
	addSide(i, t, -d[i], 0);
	addSide(t, i, 0, 0);
      }
    }
  }

  void spfa() {
    static bool book[maxn+1];
    static int que[maxn+1];
    for (int i=1; i<=n; i++) {
      dis[i] = inf;
    }
    dis[s]=0, book[s]=true, que[1]=s;
    for (int h=0, t=1; h!=t; ) {
      h = h%n+1;
      int x=que[h], y;
      book[x] = false;
      for (int i=ind[x]; i; i=link[i]) {
	y=to[i];
	if (val[i] && dis[y]>dis[x]+cost[i]) {
	  dis[y] = dis[x]+cost[i];
	  if (!book[y]) {
	    t = t%n+1;
	    que[t] = y;
	    book[y] = true;
	  }
	}
      }
    }
  }

  int dinic(int o, int flow, int &money) {
    if (o==t) {
      return flow;
    }
    int have=0;
    vis[o] = true;
    for (int i=cur[o]; i; i=link[i]) {
      if (val[i] && !vis[to[i]] && dis[to[i]]==dis[o]+cost[i]) {
	int t = dinic(to[i], min(val[i], flow-have), money);
	val[i]-=t, val[i^1]+=t, money+=cost[i]*t, have+=t;
	if (have==flow) {
	  break;
	}
      }
      cur[o] = i;
    }
    vis[o] = false;
    return have;
  }
  
  int solve() {
    int ret=0;
    if (flag) {
      return 0;
    }
    for (spfa(); dis[t]<inf; spfa()) {
      for (int i=1; i<=n; i++) {
	cur[i] = ind[i];
      }
      dinic(s, inf, ret);
    }
    for (int i=ind[s]; i; i=link[i]) {
      if (val[i]) {
	flag = true;
      }
    }
    return ret+mincost;
  }
};

int main() {
  freopen("C.in", "r", stdin);
  freopen("C.out", "w", stdout);
  
  //Blue first.
  static Net net;
  static int fa[maxn+1], r[maxn+1], b[maxn+1], er[maxn+1], eb[maxn+1], cnt[maxn+1];
  int n, m, ans=0;
  scanf("%d %d", &n, &m);
  for (int i=2; i<=n; i++) {
    scanf("%d %d %d %d %d", fa+i, r+i, b+i, er+i, eb+i);
  }
  for (int i=1; i<=m; i++) {
    int s, t, pr, pb;
    scanf("%d %d %d %d", &s, &t, &pr, &pb);
    for (int x=t; x!=s; x=fa[x]) {
      cnt[x]++;
    }
    net.addTwoSide(1, t+2, 1, 1, 0);
    net.addTwoSide(s+2, 2, 1, 1, 0);
    net.addTwoSide(t+2, s+2, 0, 1, pb-pr);
    ans += pr;
  }

  for (int i=2; i<=n; i++) {
    ans += eb[i]*cnt[i];
    net.addTwoSide(i+2, fa[i]+2, max(cnt[i]-b[i], 0), r[i], er[i]-eb[i]);
  }

  net.addTwoSide(2, 1, 0, inf, 0);
  net.build(n+2);

  int t=net.solve();
  printf("%d", net.flag ? -1 : ans+t);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
